package edu.gxnu.cetcdemo.controller;


import edu.gxnu.cetcdemo.service.UploadService;
import edu.gxnu.cetcdemo.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class UploadController {
    @Autowired
    private UploadService uploadService;
    @PostMapping("/upload")
    Result uploadtest(@RequestParam("file") MultipartFile file){
        String path = "";
        try{
            path = uploadService.uploadFile("/test",file);
        } catch (IOException e) {
            System.out.println(e);
            return new Result().build(500,"图片上传失败",null);
        }
        return uploadService.uploadResult(path);
    }

}
